<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>深复制</title>
</head>
<body>
<script>
    //通过代码的输出可以看出concat和slice并不是真正的深复制，
    // 数组中的对象元素(Object,Array等)只是复制了引用
    var arr=[1,2,3];
    var arr2=arr;
    var arr3=arr.concat();
    var arr4=arr.slice(0);
    console.log(arr===arr2);
    console.log(arr===arr3);
    console.log(arr===arr4);

    //json,parse
    var source={
        name:"source",
        child:{
            name:"child"
        }
    };
    //console.log(typeof JSON.stringify(source));//string
    var target=JSON.parse(JSON.stringify(source));
    //改变target的name值
    target.name="mengzhuo";
    console.log(source.name);//source
    console.log(target.name);//mengzhuo

    //改变target的child
    target.child.name="target child";
    console.log(source.child.name);//child
    console.log(target.child.name);//target child
</script>
</body>
</html>